import request from 'umi-request';

export async function queryAllocationList(params,isDistribute = {}) {
  // return request('/hr-ssc/api/api-admin/salary/findAllEmployeeSalaryGroup', {
  return request('/hr-ssc/api/api-admin/salary/getSalaryDistributionPage', {
    method: 'post',
    data: {
      pageNum: params.current,
      pageSize: params.pageSize,
      isDistribute : parseInt(isDistribute),
      code:params.code,
      name:params.name,
      orgname:params.orgname,
      unitname:params.unitname,
      jobname:params.jobname
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getAllsalaryGroup() {
  return request('/hr-ssc/api/api-admin/salary/findAllsalaryGroup', {
    method: 'get',
  }).then(( res) => {
    return res.data;
  });
}

export async function findSalaryUnit() {
  return request('/hr-ssc/api/api-admin/salary/findSalaryUnit', {
    method: 'get',
    params:{
      pageNum:1,
      pageSize: 1000,
    }
  }).then(( res) => {
    return res.data;
  });
}

export async function updateEmployeeSalaryGroup(params) {
  return request('/hr-ssc/api/api-admin/salary/updateSalaryDistribution', {
    method: 'post',
    data: params,
  }).then((res) => {
    return res
  });
}

export async function findEmployeeSalaryGroupById(oid) {
  return request(`/hr-ssc/api/api-admin/salary/findEmployeeSalaryGroupById/${oid}`, {
    method: 'get',
  }).then(res => {
    return res;
  });
}

export async function getSalaryGroupList(code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getSalaryGroupList`, {
    method: 'get',
    params: {code}
  }).then(res => {
    return res;
  });
}

export async function delSalaryGroup(id) {
  return request('/hr-ssc/api/api-admin/salary/deleteSalaryDistribution', {
    method: 'post',
    data: {id},
    requestType:'form'
  }).then((res) => {
    return res;
  });
}

export async function logoutSalaryDistribution(params) {
  return request('/hr-ssc/api/api-admin/salary/logoutSalaryDistribution', {
    method: 'post',
    data: params,
  }).then((res) => {
    return res
  });
}

export async function findSalaryDistributionByOid(oid) {
  return request('/hr-ssc/api/api-admin/salary/findSalaryDistributionByOid', {
    method: 'post',
    data: {oid},
    requestType:'form'
  }).then((res) => {
    return res;
  });
}
